package com.android.job.service.request;

import java.util.ArrayList;

import org.apache.http.message.BasicNameValuePair;

import android.os.Handler;
import android.util.Log;

import com.android.job.fusion.FusionCode;
import com.android.job.model.Resume;
import com.android.job.service.JSONRequest;
import com.android.job.util.CommonUtil;
import com.android.job.util.json.JSONArray;
import com.android.job.util.json.JSONException;
import com.android.job.util.json.JSONObject;

/**
 * 搜索简历请求
 * 
 * @author
 * 
 */
public class SearchResumeRequest extends JSONRequest
{

	private String salary;
	private String region;
	private String type;
	private String degree;
	private String updated;
	private String begin;

	public SearchResumeRequest(Handler handler, String httpUrl)
	{
		super(handler, httpUrl);
		// TODO Auto-generated constructor stub
	}

	public void setValues(String salary, String region, String type,
			String degree, String updated, String begin)
	{
		this.salary = salary;
		this.region = region;
		this.type = type;
		this.degree = degree;
		this.updated = updated;
		this.begin = begin;
	}

	@Override
	protected boolean parseJSONResponse(JSONObject json)
	{
		Log.i("SearchResumeRequest","===response=111==json======"+json.toString());
		if (!json.isNull("jsonData"))
		{
			JSONArray jsonArray;
			try
			{
				jsonArray = json.getJSONArray("jsonData");
				int i = 0;
				ArrayList<Resume> resumeList = new ArrayList<Resume>();
				while (!jsonArray.isNull(i))
				{
					JSONObject jsonResume = jsonArray.getJSONObject(i);
					Resume resume = new Resume();
					resume.setId(jsonResume.getString("id"));
					resume.setUserName(jsonResume.getString("userName"));
					resume.setRealName(jsonResume.getString("realName"));
					resume.setGender(jsonResume.getString("gender"));
					resume.setDegree(jsonResume.getString("degree"));
					resume.setIdentity(jsonResume.getString("identity"));
					resume.setCensus(jsonResume.getString("census"));
					resume.setBirthday(jsonResume.getString("birthday"));
					resume.setEthnic(jsonResume.getString("ethnic"));
					resume.setMarital(jsonResume.getString("marital"));
					resume.setPolitics(jsonResume.getString("politics"));
					resume.setMailingAddress(jsonResume.getString("mailingAddress"));
					resume.setHomeAddress(jsonResume.getString("homeAddress"));
					resume.setMobileNumber(jsonResume.getString("mobileNumber"));
					resume.setRegion(jsonResume.getString("region"));
					resume.setQq(jsonResume.getString("qq"));
					resume.setEmail(jsonResume.getString("email"));
					resume.setMsn(jsonResume.getString("msn"));
					resume.setSalary(jsonResume.getString("salary"));
					resume.setNature(jsonResume.getString("nature"));
					resume.setType(jsonResume.getString("type"));
					resume.setPerLogo(jsonResume.getString("perLogo"));
					resume.setRecentType(jsonResume.getString("recentType"));
					resume.setRecentYear(jsonResume.getString("recentYear"));
					resume.setPersonType(jsonResume.getString("personType"));
					resume.setRegIp(jsonResume.getString("regIp"));
					resume.setRegDate(jsonResume.getString("regDate"));
					resume.setEditDate(jsonResume.getString("editDate"));
					resume.setViewTime(jsonResume.getString("viewTime"));
					resume.setLastLoginIp(jsonResume.getString("lastLoginIp"));
					resume.setLastLoginDate(jsonResume.getString("lastLoginDate"));
					resume.setLoginTime(jsonResume.getString("loginTime"));
					resume.setEduStr(jsonResume.getString("eduStr"));
					resume.setEduCateStr(jsonResume.getString("eduCateStr"));
					resume.setWorkExpStr(jsonResume.getString("workExpStr"));
					resumeList.add(resume);
					i++;
				}
				Log.i("free.lang","===CommonUtil.sendMessage======");
				CommonUtil.sendMessage(handler, FusionCode.RETURN_JSONOBJECT,
						resumeList);
			}
			catch (JSONException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		return true;
	}

	@Override
	protected void appendMainBody()
	{
		this.paramsters = new ArrayList();
		try
		{
			jsonObject = new JSONObject();
			jsonObject.put("requestType", "searchResumes");
			JSONObject userJson = new JSONObject();
			userJson.put("salary", salary);
			userJson.put("region", region);
			userJson.put("type", type);
			userJson.put("degree", degree);
			userJson.put("updateTime", updated);
			userJson.put("begin", begin);
			jsonObject.put("jsonData", userJson);
			paramsters.add(new BasicNameValuePair("jsonData", jsonObject.toString()));
			Log.i("SearchResumeRequest","===request===json======"+jsonObject.toString());
		}
		catch (JSONException e)
		{
			e.printStackTrace();
		}
	}
}
